package com.video.moderation.repository;

import com.video.moderation.entity.MemberLog;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface MemberLogRepository extends JpaRepository<MemberLog, Long> {

    @Query(value = "SELECT COUNT(*) as recordCount, DATE_FORMAT(log_time, '%W') as week " +
            "FROM member_log WHERE YEARWEEK(DATE_FORMAT(log_time, '%Y-%m-%d')) = YEARWEEK(NOW()) - 1 " +
            "AND member_id = :memberId " +
            "GROUP BY DATE(log_time) " +
            "ORDER BY FIELD(week, 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday')", nativeQuery = true)
    List<Map<String,String>> queryLastWeekModeratedData(@Param("memberId") Integer memberId);

}
